{include file="base/_meta" /}
</head>
<body>

<form class="layui-form model-form" id="modelAuthForm" lay-filter="modelAuthForm">
    <div class="layui-form-item">
        <label class="layui-form-label">标题</label>
        <div class="layui-input-inline">
            <input type="text" name="title" required lay-verify="required" placeholder="请输入标题" autocomplete="off"
                   class="layui-input" value="{$content['label']|default=''}">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label"></label>
        <div class="layui-input-block">
            <button class="layui-btn" lay-filter="*" lay-submit>完成编辑</button>
        </div>
    </div>
</form>

{include file="base/_script" /}
<script>
    layui.use(['layer', 'form','notice'], function () {
        var $ = layui.jquery
            , layer = layui.layer
            , form = layui.form
            , name = "radio-<?php echo microtime(true)*10000;?>"
            , content = {}
            ,notice = layui.notice;

        form.on('submit(*)', function (data) {
            let field = data.field

            let required = false
            if(field.required == 'on'){
                required = true
            }
            content.label = field.title
            content.name = name
            content.required = required
            content.type = 'title'
            content.values = []

            $.post("{:url('question/saveTemp2')}",{content:content,question_id:"{$question_id}",index:"{$index}",insert:"{$insert}"},function (ret) {
                if (ret.code == 0){
                    layer.msg(ret.msg,{icon:6,time:1500},function () {
                        parent.layer.closeAll();
                    })
                }else{
                    layer.msg(ret.msg,{icon:5,time:1500})
                }
            });
            return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
        });

        $(".add").click(function(){
            var html = '<tr>\n' +
                '                    <td><input type="text" name="values" placeholder="请输入标题" autocomplete="off"\n' +
                '                               class="layui-input"></td>\n' +
                '                    <td>\n' +
                '                        <button type="button" class="layui-btn layui-btn-sm del">删除</button>\n' +
                '                        <button type="button" class="layui-btn layui-btn-sm up">上移</button>\n' +
                '                        <button type="button" class="layui-btn layui-btn-sm down">下移</button>\n' +
                '                    </td>\n' +
                '                </tr>'

            $("#tbody").append(html)
            $('#tbody').children(':last-child').find('input').show().focus();

        })
        $("#tbody").on('click','.del',function(){
            $(this).parent().parent().remove()
        })
        $("#tbody").on('click','.down',function(){
            $(this).parent().parent().next("tr").after($(this).parent().parent());
        });
        $("#tbody").on('click','.up',function(){
            $(this).parent().parent().prev("tr").before($(this).parent().parent());
        });

        var tableHd = $("#thead");
        var tableTop = tableHd.offset().top;
        $(window).scroll(function() {
            var _t = $(window).scrollTop();

            if (_t - tableTop >= 0) {
                //table-header 已经到窗口顶部了
                tableHd.css({
                    "position": "fixed"
                })
            } else {
                tableHd.css({
                    "position": "static"
                })
            }
        });
    })

</script>


</body>
</html>
